import request from "../utils/request.js";
import qs from 'qs';
//用户登录
export function login(data){
    return request({
        url: "/login",
        method: "post",
        data:{
            "phone": data.phone,
            "password": data.password,
            "code":data.code
       }
    })
}

//获取用户信息
export function getUserList({ currentPage = 1, pageSize = 5 } = {}) {
    return request({
        url: '/user',
        method: 'get',
        params: {
            currentPage,
            pageSize
        }
    });
}
//添加用户信息
export function addUser(data){
    return request({
        url:'/user',
        method:'post',
        data:data
    })
}
//修改用户信息
export function updateUser(data){
    return request({
        url:'/user',
        method:'put',
        data:data
    })
}
//删除用户信息
export function deleteUser(id){
    return request({
        url: '/user/'+id,
        method:'delete',
    })
}

//批量删除
export const deleteBatch = ids =>
    request({
        url: '/deleteBatch',
        method: 'delete',
        params: { ids },
        paramsSerializer: params => {
            return qs.stringify(params, { arrayFormat: 'repeat' });
        }
    });


// 状态按钮更新，更新用户状态
export function updateUserStatus(id, status) {
    return request({
        url: `/users/${id}/status`,   // 动态路径
        method: 'put',
        data: { status }              // 只传 status
    })
}
//根据状态和用户名查询
export function queryUsers(params) {
    return request({
        url: '/query',
        method: 'get',
        params
    })
}
